package com.hkfrich.system.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import com.hkfrich.common.controller.BaseController;
import com.hkfrich.common.utils.ConvertUtils;
import com.hkfrich.common.utils.ResultUtils;
import com.hkfrich.system.domain.SysNotice;
import com.hkfrich.system.service.SysNoticeService;
//import com.hkfrich.common.core.page.TableDataInfo;

/**
 * @ClassName 通知公告Controller
 * @Desscription
 * @Author _Heishuai
 * @Date 2023-01-29 17:14:34
 * @Version 1.0
 */
@Controller
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController {

    @Autowired
    private SysNoticeService sysNoticeService;

    /**
     * 通过条件查询单个通知公告 不分页
     */
    @RequestMapping("/getOne")
    @ResponseBody
    public ResultUtils getOne(SysNotice sysNotice)
    {
        QueryWrapper<SysNotice> query = initBaseQueryWrapper(sysNotice);
        SysNotice one = sysNoticeService.getOne(query);
        return ResultUtils.success(one,"通知公告查询成功");
    }

    /**
     * 通过id查询单个通知公告
     */
    @RequestMapping("/getOneById")
    @ResponseBody
    public ResultUtils getOneById(@RequestBody String paramsStr)
    {
        JSONObject params = getBodyParamsByStr(paramsStr);
        Long id = params.getLong("id");
        SysNotice one = sysNoticeService.getById(id);
        return ResultUtils.success(one,"通知公告查询成功");
    }

    /**
     * 查询通知公告列表  分页
     */
    @RequestMapping("/list")
    @ResponseBody
    public ResultUtils list(@RequestBody SysNotice sysNotice)
    {
        Page<SysNotice> page = initBaseQueryPageWrapper(sysNotice);
        QueryWrapper<SysNotice> query = initBaseQueryWrapper(sysNotice);
        Page<SysNotice> pageGrid = sysNoticeService.page(page, query);
        return ResultUtils.success(pageGrid,"通知公告列表查询成功");
    }

    /**
     * 新增通知公告
     */
    @RequestMapping("/save")
    @ResponseBody
    public ResultUtils save(@RequestBody SysNotice sysNotice)
    {
        return ResultUtils.success(sysNoticeService.save(sysNotice),"通知公告保存成功");
    }

    /**
     * 修改通知公告
     */
    @RequestMapping("/updateById")
    @ResponseBody
    public ResultUtils updateById(@RequestBody SysNotice sysNotice)
    {
        return ResultUtils.success(sysNoticeService.updateById(sysNotice),"通知公告修改成功");
    }

    /**
     * 删除通知公告
     */
    @RequestMapping("/removeById")
    @ResponseBody
    public ResultUtils removeById(@RequestBody String paramsStr)
    {
        JSONObject params = getBodyParamsByStr(paramsStr);
        Long id = params.getLong("id");
        return ResultUtils.success(sysNoticeService.removeById(id),"通知公告删除成功");
    }

    /**
     * 批量删除通知公告
     */
    @RequestMapping("/removeByIds")
    @ResponseBody
    public ResultUtils removeByIds(@RequestBody String paramsStr)
    {
        JSONObject params = getBodyParamsByStr(paramsStr);
        String ids = params.getString("ids");
        List<Long> list = ConvertUtils.toList(ids);
        return ResultUtils.success(sysNoticeService.removeByIds(list),"批量删除通知公告成功");
    }

}
